package com.youlu.campus.web.group.controller;

import com.youlu.campus.base.base.PageQueryRequest;
import com.youlu.campus.service.invite.UserInviteService;
import com.youlu.campus.web.group.dto.request.CreateGroupRequest;
import com.youlu.campus.web.group.dto.request.GroupMemberRequest;
import com.youlu.campus.web.group.dto.request.GroupQuitRequest;
import com.youlu.campus.web.group.dto.request.GroupRankingRequest;
import com.youlu.campus.web.group.dto.request.UniversityGroupRequest;
import com.youlu.campus.web.group.service.GroupRankingListService;
import com.youlu.campus.web.group.service.GroupService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 小组
 *
 * @author: zgz
 * @date: 2020/8/13 13:36
 */
@RestController
public class GroupController {

    @Autowired
    private GroupService groupService;

    @Autowired
    private GroupRankingListService groupRankingListService;

    @Autowired
    private UserInviteService userInviteService;

    /**
     * 创建小组
     * 备注：创建小组
     */
    @PostMapping("/mini-app/group/create")
    public QResult createGroup(@RequestBody @Valid CreateGroupRequest request) {
        return QResult.success(groupService.createGroup(request));
    }

    /**
     * 编辑小组
     * 备注：编辑小组
     */
    @PostMapping("/mini-app/group/edit")
    public QResult editGroup(@RequestBody @Valid CreateGroupRequest request) {
        return QResult.success(groupService.editGroup(request));
    }

    /**
     * 小组主页
     * 备注：小组主页
     */
    @GetMapping("/mini-app/group/home")
    public QResult getGroupHomeInfo(String groupId) {
        return QResult.success(groupService.getGroupHomeInfo(groupId));
    }

    /**
     * 小组成员列表
     * 备注：小组成员列表
     */
    @PostMapping("/mini-app/group/members")
    public QResult getGroupMembers(@RequestBody @Valid GroupMemberRequest request) {
        return QResult.success(groupService.getGroupMembers(request));
    }

    /**
     * 小组累计打卡榜
     * 备注：小组累计打卡榜
     */
    @PostMapping("/mini-app/group/sign/ranking")
    public QResult findSignCount(@RequestBody @Valid GroupRankingRequest request) {
        return QResult.success(groupRankingListService.findSignCount(request));
    }

    /**
     * 小组连续打卡榜
     * 备注：小组连续打卡榜
     */
    @PostMapping("/mini-app/group/sign/series/ranking")
    public QResult findSignSeriesCount(@RequestBody @Valid GroupRankingRequest request) {
        return QResult.success(groupRankingListService.findSignSeriesCount(request));
    }

    /**
     * 小组邀请榜
     * 备注：小组邀请榜
     */
    @PostMapping("/mini-app/group/invite/ranking")
    public QResult findInviterCount(@RequestBody @Valid GroupRankingRequest request) {
//        userInviteService.findInviteCount(request)
        return QResult.success(true);
    }

    /**
     * 小组累计打卡榜-我的排名
     * 备注：小组累计打卡榜-我的排名
     */
    @GetMapping("/mini-app/group/sign/ranking/my")
    public QResult mySignCountRank(String groupId) {
        return QResult.success(groupRankingListService.mySignCountRank(groupId));
    }

    /**
     * 小组连续打卡榜-我的排名
     * 备注：小组连续打卡榜-我的排名
     */
    @GetMapping("/mini-app/group/sign/series/ranking/my")
    public QResult mySignSeriesCountRank(String groupId) {
        return QResult.success(groupRankingListService.mySignSeriesCountRank(groupId));
    }

    /**
     * 小组邀请榜-我的排名
     * 备注：小组邀请榜-我的排名
     */
    @GetMapping("/mini-app/group/invite/ranking/my")
    public QResult myInviteCountRank() {

//        userInviteService.myInviteCountRank()
        return QResult.success(true);
    }

    /**
     * 加入小组
     * 备注：加入小组
     */
    @GetMapping("/mini-app/group/join")
    public QResult joinGroup(String groupId) {
        return QResult.success(groupService.joinGroup(groupId));
    }

    /**
     * 退出小组
     * 备注：退出小组
     */
    @PostMapping("/mini-app/group/quit")
    public QResult quitGroup(@RequestBody @Valid GroupQuitRequest request) {
        return QResult.success(groupService.quitGroup(request));
    }

    /**
     * 获取加入了小组信息
     * 备注：获取加入了小组信息
     */
    @GetMapping("/mini-app/group/my/join")
    public QResult getMyJoinGroup() {
        return QResult.success(groupService.getMyJoinGroup());
    }

    /**
     * 获取大学组织列表
     * 备注：获取大学组织列表
     */
    @PostMapping("/mini-app/university/group")
    public QResult getUniversityGroups(@RequestBody @Valid UniversityGroupRequest request) {
        return QResult.success(groupService.getUniversityGroups(request));
    }

    /**
     * 获取组织活力排行榜
     * 备注：获取组织活力排行榜
     */
    @PostMapping("/mini-app/group/ranking")
    public QResult getGroupRank(@RequestBody @Valid PageQueryRequest request) {
        return QResult.success(groupService.getGroupRank(request));
    }

    /**
     * 获取我的组织活力排行榜
     * 备注：获取我的组织活力排行榜
     */
    @GetMapping("/mini-app/group/ranking/my")
    public QResult getMyGroupRank() {
        return QResult.success(groupService.getMyGroupRank());
    }

    /**
     * 获取解散弹窗
     * 备注：获取解散弹窗
     */
    @GetMapping("/mini-app/group/dissolution/popup")
    public QResult getGroupDissolutionPopup() {
        return QResult.success(groupService.getGroupDissolutionPopup());
    }
}